#!/bin/sh
#
# description: Enable and disable pathed RootApp
#
mos=/usr/local/etc/mos
rcS="/usr/local/etc/rcS"

case "$1" in
  start | stop | restart | status)
	;;
  enable)
	echo "Enabling pathed RootApp..."
	#check for already enabled
	if [ ! -f /usr/local/etc/RootApp ] ; then
	  echo "  Patching rcS..."
	  cat $rcS | sed 's/^\(.*\)\.\/RootApp DvdPlayer\(.*\)$/\1\/usr\/local\/etc\/RootApp DvdPlayer\2/' > $rcS.new
	  mv $rcS.new $rcS
	  chmod +x $rcS
	  echo "  Copying files..."
	  cp $mos/rootapp/RootApp /usr/local/etc/
	  cp $mos/rootapp/rc.suspend /usr/local/etc/
	  cp $mos/rootapp/rc.wakeup /usr/local/etc/
      #cp $mos/rootapp/wakeup /usr/local/etc/
	fi
	echo "Patched RootApp enabled"
	echo "Please, reboot device!"
	;;
  disable)
	echo "Disabling patched RootApp..."
	#check for already disabled
	if [ -f /usr/local/etc/RootApp ] ; then
	  echo "  Patching rcS..."
	  cat $rcS | sed 's/^\(.*\)\/usr\/local\/etc\/RootApp DvdPlayer\(.*\)/\1\.\/RootApp DvdPlayer\2/' > $rcS.new
	  mv $rcS.new $rcS
	  chmod +x $rcS
	  echo "  Stopping GUI..."
	  stopall
	  echo "  Removing files..."
	  rm /usr/local/etc/RootApp 
	  rm /usr/local/etc/rc.suspend
	  rm /usr/local/etc/rc.wakeup
	  #rm /usr/local/etc/wakeup
	fi
	echo "Patched RootApp disabled"
	echo "Please, reboot device!"
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status|enable|disable}"
esac

exit $?
